package com.zhida.smartcontrol;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import com.jay.tools.base.BaseFragment;
import com.jay.tools.base.ProxyActivity;
import com.jay.tools.utils.EventBusUtils;
import com.zhida.smartcontrol.launch.login.LoginFragment;
import com.zhida.smartcontrol.launch.login.bean.LoginBean;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.List;

import me.yokeyword.fragmentation.core.SupportHelper;

public class MainActivity extends ProxyActivity {

    @Override
    protected BaseFragment setRootFragment() {
        return new LoginFragment();
    }

    @Override
    protected void initDatas(Bundle savedInstanceState) {
        EventBusUtils.register(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void reLogin(LoginBean bean) {
        List<Fragment> fragments = getSupportFragmentManager().getFragments();
        for (Fragment fragment : fragments) {
            getSupportFragmentManager().beginTransaction().remove(fragment)
                    .commitAllowingStateLoss();
        }
        loadRootFragment(com.jay.tools.R.id.fragment_container, new LoginFragment());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBusUtils.unregister(this);
    }
}
